// Local
#include "testrepo.h"
#include "repository.h"
#include "hop.h"
#include "util.h"

// QtTest
#include <QTest>

// QtCore
#include <QDebug>
#include <QDir>

QTEST_MAIN(testRepo);

void testRepo::OpenOneHop()
{
    qDebug() << "Current directory : " << QDir::currentPath();
    QDir curDir = QDir::current();

    Repository Repo(curDir.path());
    Repo.OpenWrite();

    Hop *zeHop = new Hop("Test Hop",1,9.5,0,HUAroma,5);
    QVERIFY(0==Repo.AddHop(zeHop));
    Repo.Close();
    zeHop->Release();

    Repository Repo2(curDir.path());
    Repo2.OpenRead();
    QStringList HopList = Repo2.ListHopNames();
    QVERIFY(HopList.size()==1);
    for (int i=0;i<HopList.size();i++)
        qDebug() << HopList[i];

    Hop *searchedHop = Repo2.SearchHop(HopList[0]);
    QVERIFY(searchedHop);
    if (searchedHop)
        searchedHop->Release();
    QVERIFY(*searchedHop==*zeHop);

    // Remove "Hops" directory
    RecursiveRemove(curDir.filePath("Hops"));
}
